/**
 * 
 */
package database;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Ken
 *
 */
public class Database {	
	private String _name;
	private List<Table> _tables;
	
	public Database() {
		_tables = new ArrayList<Table>();
	}

	public Database(String name, List<Table> table){
		_name = name;
		_tables = table;
	}
	
	@Override
	public String toString() {
		return _name;
	}
	
	/**
	 * @return the _name
	 */
	public String get_name() {
		return _name;
	}

	/**
	 * @param _name the _name to set
	 */
	public void set_name(String _name) {
		this._name = _name;
	}

	/**
	 * @return the _tables
	 */
	public List<Table> get_tables() {
		return _tables;
	}

	/**
	 * @param _tables the _tables to set
	 */
	public void set_tables(List<Table> _tables) {
		this._tables = _tables;
	}

	public Table getTable(String name) {
		for (int i = 0; i < _tables.size(); i++) {
			if (_tables.get(i).get_name().equalsIgnoreCase(name))
				return _tables.get(i);
		}
		return null;
	}
	
	public boolean addTable(String name) {
		Table t = getTable(name);
		if (t != null)
			return false;
		t = new Table();
		t.set_name(name);
		_tables.add(t);
		return true;
	}

	public Table getTable(int i) {
		if (i < 0 || i >= _tables.size())
			return null;
		return _tables.get(i);
	}

	public void removeTable(String tableName) {
		int index = 0;
		while (index < _tables.size()) {
			Table t = _tables.get(index);
			if (t.get_name().equalsIgnoreCase(tableName)) {
				_tables.remove(index);
				return;
			}				
			index++;
		}
	}
}
